<template>
	<view>
		<!-- 城市定位 + tub -->
		<view class="Content-left">
			<view class="city">
				<view>
					<button style="border: 0px;" class="uni-nav-bar-text" :loading="isLoading">{{ city }}</button>
				</view>
				<!-- <uni-icons type="down" color="#666" size="14" /> -->
			</view>
		</view>
		
	</view>
		
</template>

<script>
	export default {
		data() {
			return {
				isLoading: false,
				reson:'',
				val:'消息中心',
				city: '定位中',
				searchValue: '123123',
				latitude: '', //纬度
				longitude: '', //经度
			};
		},
		mounted() {
			this.isLoading = true;
			      setTimeout(() => {
			        this.isLoading = false;
						// let _this = this  //为确保回调函数能正常使用，先保存在一个变量中
						// 获取位置
						uni.getLocation({
							success:({
								longitude,
								latitude
								}) => {	
								//diaoydiao调用高德地图API，把经纬度转换为地址极坐标
								uni.request({
									url:'https://restapi.amap.com/v3/geocode/regeo',
									data:{
										key:'d8bad66a4b3f6dfa309972ae74a089ae',
										location:longitude + ',' + latitude,
									},
									success:(res) => {
										this.reson = res.data.regeocode.formatted_address
										uni.showModal({
											title: '通知',
											content: '当前位置为：' + this.reson,
											showCancel: false,
											cancelText: '1',
											confirmText: '知道了',
											success: res => {},
											fail: () => {},
											complete: () => {}
										});
										this.city = res.data.regeocode.addressComponent.district
										console.log(this.city);
									}
									
								})
							}
						})	
					
			      }, 1500);	
		},
		methods:{
			// this.point = uni.getMenuButtonBoundingClientRect()
			
		}
	}
</script>

<style lang="scss">
.Content-left{
			flex: 1;
			display: flex;
			align-items: center;
			justify-content: center;
			.city{
				display: flex;
				font-size: 10px;
				button::after{ border: none;} 
				button{
					font-size: 10px;
				}
			}
		}
</style>
